﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace MainService
{
    [DataContract]
    public class UserDetails
    {
        [DataMember]
        public string UserName { get; set; }
        private string _password;

        [DataMember]
        public string HashCode { get; set; }

        [DataMember]
        public string Password { set { _password = value; } get { return _password; } }

        [DataMember]
        public string Company { get; set; }

        [DataMember]
        public UserAccessDetails UserAccess { get; set; }

        [DataMember]
        public string EmailId { get; set; }

        [DataMember]
        public string LastLogin { get; set; }

        private bool _isValidated;
        [DataMember]
        public bool IsUserValidated { get { return _isValidated; } set { _isValidated = value; } }

        [DataMember]
        public string CreateDate { get; set; }

        [DataMember]
        public string LoginMessage { get; set; }

        [DataMember]
        public int DeviceLimit { get; set; }

        [DataMember]
        public List<string> ServiceList { get; set; }

        [DataMember]
        public Dictionary<int,string> GetServiceList { get; set; }

        [DataMember]
        public int ClientId { get; set; }

        public UserDetails()
        {

        }

        public UserDetails ValidateUser()
        {
            UserOperations _uOps = new UserOperations();
            UserDetails _usr = _uOps.ValidateUser(UserName, _password);
            return _usr;
        }
        
        public string AddUser()
        {
            UserOperations _usr = new UserOperations();
            return _usr.AddUser(UserId,EmailId, UserName, _password, Company,DeviceLimit,ClientId,ServiceList,HashCode);
        }
       
        [DataMember]
        public int UserId { get; set; }

        internal string DeleteUser()
        {

            UserOperations _usr = new UserOperations();
            return _usr.DeleteUser(UserId, ClientId,HashCode);
        }

        internal string UpdateUser()
        {
            UserOperations _usr = new UserOperations();
            return _usr.UpdateUser(UserId,UserName, _password,DeviceLimit, ClientId, ServiceList,HashCode);
        }

        internal static List<UserDetails> GetUserList(int clientId, string HashCode)
        {
            UserOperations _usr = new UserOperations();
            return _usr.ListUsers(clientId, HashCode);
        }

        internal static UserDetails ListAppUser(int userId, int clientId, string hashCode)
        {
            UserOperations _usr = new UserOperations();
            return _usr.ListUser(userId, clientId, hashCode);
        }
    }

    [DataContract]
    public class UserAccessDetails
    {
        public List<string> Databases { get; set; }
        public List<string> Services { get; set; }
    }
}